package com.atguigu.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.pojo.ExcelStudentDTO;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lsyandwh:
 * @create 2022-12-05 16:21
 */
public class StudentListener extends AnalysisEventListener<ExcelStudentDTO> {

    List<ExcelStudentDTO> list = new ArrayList<>();

    @Override
    public void invoke(ExcelStudentDTO excelStudentDTO, AnalysisContext analysisContext) {

        list.add(excelStudentDTO);

        if(list.size()%100 == 0){
            System.out.println("读取了100行数据，解析一次");
            list.clear();
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

        System.out.println(list);
        System.out.println("数据解析完成");
    }
}
